package com.javabynataraj.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.javabynataraj.dbcon.DBConnection;

public class LoginDao {

	public int insert(String un,String pw){
		int r=0;
		PreparedStatement ps = null;
		//get connection object from DBConnection class
		Connection con = DBConnection.dbConn();
		System.out.println("Connection"+con);

		try{
			//use PreparedStatement to insert the values of username and password
			ps=con.prepareStatement("insert into login(username,password) values(?,?)"); 
			ps.setString(1, un);
			ps.setString(2, pw);
			r = ps.executeUpdate();	
		}
		catch(SQLException ex) {
			try {
				ps.close();
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.err.println("SQLException: " + ex.getMessage());
		}
		return r;

	}
}
